#include "aduc812.h"
#include "fifo.h"

void new_fifo(struct FIFO * fifo) {
	fifo->head = 0;
	fifo->tail = 0;
	fifo->empty = 1;
	fifo->full = 0;
}

char put(struct FIFO * fifo, char value) {
	if (!fifo->full) {
		fifo->array[fifo->tail] = value;
		fifo->tail = (fifo->tail + 1 == SIZE) ? 0 : fifo->tail + 1;
		fifo->full = (fifo->head == fifo->tail) ? 1 : 0;
		fifo->empty = 0;
		return 1;
	}
	return 0;
}

char get(struct FIFO * fifo, char * value) {
	if (!fifo->empty) {
		* value = fifo->array[fifo->head];
		fifo->head = (fifo->head + 1 == SIZE) ? 0 : fifo->head + 1;
		fifo->empty = (fifo->head == fifo->tail) ? 1 : 0;
		fifo->full = 0;
		return 1;
	}
	return 0;
}
